<?php
require_once("include/auth.php");



$userName = $_POST['userName'];
$password = $_POST['password'];
$confirmPassword = $_POST['confirmPassword'];
$userType = $_POST['userType'];
$errors = array();

//echo("$userName $password $confirmPassword $userType");

if ($userName==""){
    array_push($errors, "1");
}
if ($password == ""){
    array_push($errors,"5");
}
elseif ($password!=$confirmPassword){
    array_push($errors,"2");
}
if ($userType == 0){
    array_push($errors,"3");
}
//one or more errors exist
if ( sizeof($errors) == 0){
    $user = create_account($userName,$password,$userType);
    if ($user){
        log_in($userName);
        if ($userType==1){
            redirect("personalinformation.php");
        }
        //todo:redirect to page for faculty

        //echo(print_r($user));
    }
    else{
        array_push($errors,"4");
    }
}
if ( sizeof($errors)> 0){
    $msg = join(',', $errors);
    redirect("create_account.php",array("errorMsg" =>$msg,"userName"=>$userName, "userType"=>$userType ));
    //header("Location: create_account.php?errorMsg=$msg&userName=$userName&userType=$userType");
}


?>